﻿
@{
    ViewBag.MainMenu = "Campaign";
    ViewBag.LeftMenu = "ShakingLottery";

    ViewBag.Title = "摇一摇抽奖";
    Layout = "~/Views/Shared/_Layout.cshtml";
}



<script language="javascript">

    var _mode = "create";//modify
    var _validator;

    var _shakingLottery;

    $(document).ready(function ()
    {
        setOnlyMember();

        _validator = $("#formExtra").validate({
            onfocusout: false,
            onkeyup: false,
            showErrors: showValidationErrors,
            rules: {
                "txtChanceTimes": {
                    required: true,
                    number: true,
                    digits: true,
                    range: [1, 999]
                }
            },
            messages: {
                "txtChanceTimes": {
                    required: "请输入每次摇奖机会；",
                    number: "每次摇奖机会请输入有效整数字；",
                    digits: "每次摇奖机会请输入有效整数字；",
                    range: "每次摇奖机会请介于 1 到 999 之间；"
                }
            }
        });

        loadData();
    });

    function loadData()
    {
        var id = getQueryString("id");
        if (id == undefined || id == "")
        {
            return;
        }

        _mode = "modify";
        $("#btnRemove").show();

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/Campaign/GetShakingLotteryBundle?id=" + id,
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR)
            {
                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    var campaign = data.Data.Campaign;
                    _shakingLottery = data.Data.ShakingLottery;

                    setCampaign(campaign);
                    $("#txtChanceTimes").val(_shakingLottery.ChanceTimes);
                    $("#selectMode").find("option[value='" + _shakingLottery.Mode + "']").attr("selected", true);
                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function save()
    {
        if (_campaignBaseInfoValidator.form() == false || _validator.form() == false)
        {
            return;
        }

        var campaign = getCampaign();

        if (_shakingLottery == undefined || _shakingLottery == null)
        {
            _shakingLottery = new Object();
        }

        _shakingLottery.ChanceTimes = $("#txtChanceTimes").val();
        _shakingLottery.Mode = $("#selectMode").val();

        var bundle = new Object();
        bundle.Campaign = campaign;
        bundle.ShakingLottery = _shakingLottery;

        var url = "/Api/Campaign/CreateShakingLottery";

        if (_mode == "modify")
        {
            campaign.Id = $("#txtId").val();
            url = "/Api/Campaign/UpdateShakingLottery";
        }

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: url,
            type: "POST",
            dataType: "json",
            data: JSON.stringify(bundle),
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    window.location.href = "/Campaign/ShakingLottery_Preparatory";

                } else
                {
                    layer.close(loadLayerIndex);
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function cancel()
    {
        window.location.href = "/Campaign/ShakingLottery_Preparatory";
    }

    function removeData()
    {
        var id = $("#txtId").val();
        if (id == undefined || id == "")
        {
            return;
        }

        var msg = "是否确认删除该活动？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function ()
        {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/RemoveShakingLottery?id=" + id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR)
                {
                    if (data.Success)
                    {
                        window.location.href = "/Campaign/ShakingLottery_Preparatory";
                    } else
                    {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest)
                {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

</script>


<div style=" margin-top:25px; margin-left:10px;" class="font_black_24">
    发起活动
</div>

<div class="divDotLine" style="margin-top:15px;"></div>

<div style="margin-top:25px;">
    @Helpers.CampaignBaseEdit()
</div>

<div style="margin-top:0px;">
    <form id="formExtra">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            @*<tr>
                <td height="36">参与所需积分：</td>
                <td>
                    <input id="txtPoint" name="txtPoint" type="text" class="input_16" style="width:130px; " value="0" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td valign="top">
                    <div class="font_gray_13" style="width: 96%; margin-bottom: 10px;">
                        参与活动需消费指定量的积分，设置为0表示不需要消费积分即可参与。
                    </div>
                </td>
            </tr>*@
            <tr>
                <td width="200" height="36">参与方式：</td>
                <td>
                    <select id="selectMode" name="selectMode" class="input_16" style="width:200px;">
                        <option value="0" selected>只能参与一次</option>
                        @*<option value="1">可多次参与</option>*@
                        <option value="2">多周期滚动模式</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td height="36">每次/每周期摇奖机会：</td>
                <td>
                    <input id="txtChanceTimes" name="txtChanceTimes" type="text" class="input_16" style="width:130px; " value="1" maxlength="3" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td valign="top">
                    <div class="font_gray_13" style="width: 96%; margin-bottom: 10px;">
                        每次参与可得到的摇奖机会，但是只允许中奖一次。
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>

<div style="margin-top:25px;">
    <div style="float:right;">
        <input name="btnRemove" type="button" class="btn_red" id="btnRemove" value="删 除" style="display:none" onclick="removeData()" />
    </div>
    <div style="float:left">
        <input name="btnSave" type="button" class="btn_blue" id="btnSave" value="保 存" onclick="save()" />
        <input name="btnCancel" type="button" class="btn_blue" id="btnCancel" value="取 消" onclick="cancel()" />
    </div>
    <div style="clear:both"></div>
</div>

@Helpers.FileUpload()


